package com.derongonline.activity;

import android.app.Activity;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TextView;

import com.derongonline.R;

import java.util.ArrayList;
import java.util.List;

public class NavigationTabActivity extends Activity {

    private Context mContex = this;
    private TabHost mTabHost;

    private String HOME = "home";
    private String LOAN = "loan";
    private String USER = "user";

    private List<LinearLayout> menuItemList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigation_tab);

        menuItemList = new ArrayList<LinearLayout>();

        mTabHost = (TabHost) findViewById(R.id.tabhost);
        mTabHost.setup();

        mTabHost.addTab(mTabHost.newTabSpec("home").setIndicator(getMenuItem(R.drawable.home_btn, HOME)));
        mTabHost.addTab(mTabHost.newTabSpec("loan").setIndicator(getMenuItem(R.drawable.loan_btn, LOAN)));
        mTabHost.addTab(mTabHost.newTabSpec("user").setIndicator(getMenuItem(R.drawable.user_btn, USER)));
    }

    public View getMenuItem(int imgID, String textID) {
        LinearLayout ll = (LinearLayout) LayoutInflater.from(mContex).inflate(R.layout.tab_item, null);
        ImageView imgView = (ImageView) ll.findViewById(R.id.icon);
        imgView.setBackgroundResource(imgID);
        TextView textView = (TextView) ll.findViewById(R.id.name);
        textView.setText(textID);
        menuItemList.add(ll);
        return ll;
    }
}
